def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def a(num):
    g = [x for x in range(num - 1, 1, -1) if is_prime(x)]
    return min(g, key=lambda x: abs(num - x))

b = input("Введите три слова: ")
words = b.split()

if len(words) != 3:
    print("Wrong input")
else:
    number = ""
    for word in words:
        if word == "zero":
            number += "0"
        elif word == "one":
            number += "1"
        elif word == "two":
            number += "2"
        elif word == "three":
            number += "3"
        elif word == "four":
            number += "4"
        elif word == "five":
            number += "5"
        elif word == "six":
            number += "6"
        elif word == "seven":
            number += "7"
        elif word == "eight":
            number += "8"
        elif word == "nine":
            number += "9"
        else:
            print("Wrong input")
            break
    
    if number.isdigit() and len(number) == 3:
        number = int(number)
        p = a(number)
        print(p)
    else:
        print("Wrong input")